package gui.panels;

import gui.tools.ActionHandler;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mysql.LocationQueries;
import objects.Location;

public class LocationPanel extends JPanel {
	public Location loccurrentEntry;
	public LocationQueries locQueries;
	public List<Location> locResults;
	public int locnumberOfEntries = 0;
	public int locCurrentEntryIndex = 0;
	
	public JTextField addressText;
	private JLabel addressLabel;
	public JTextField stateText;
	private JLabel stateLabel;
	
	public JButton next;
	public JButton previous;
	public JPanel navigatePanel;
	public JTextField index;
	private JPanel displayPanel;
	public JButton add;
	
	public LocationPanel(ActionHandler ac) {
		getData();
		addressLabel = new JLabel("Address:");
		addressText = new JTextField(10);
		stateLabel = new JLabel("State:");
		stateText = new JTextField(10);
		
		next = new JButton("Next");
		previous = new JButton("Previous");
		navigatePanel = new JPanel();
		index = new JTextField(2);
		displayPanel = new JPanel();
		add = new JButton("Add new location");
		
		addressText.setEditable(false);
		stateText.setEditable(false);
		
		setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

		next.addActionListener(ac);
		previous.addActionListener(ac);
		navigatePanel.setLayout(new BoxLayout(navigatePanel, BoxLayout.X_AXIS));
		navigatePanel.add(previous);
		navigatePanel.add(Box.createHorizontalStrut(10));
		navigatePanel.add(index);
		navigatePanel.add(Box.createHorizontalStrut(10));
		navigatePanel.add(next);
		add(navigatePanel);

		displayPanel.setLayout(new GridLayout(2, 2, 4, 4));
		displayPanel.add(addressLabel);
		displayPanel.add(addressText);
		displayPanel.add(stateLabel);
		displayPanel.add(stateText);
	
		add.addActionListener(ac);

		add(displayPanel);
		add(add, BorderLayout.SOUTH);
	}

	public void getData() {
		locQueries = new LocationQueries();
		locResults = locQueries.getAllLocations();
	}
}
